﻿ 
@using Ema.Control
@model  Ema.Models.XtModel.SubXtUser

@{
    ViewBag.Title = "添加用户";
}

<div class="am-g">
    <div class="am-u-md-8 am-u-md-centered">
        <div class="am-panel" style="height: 1000px">
            <div class="am-panel-bd">
                @using (Html.BeginForm("Add", "User", FormMethod.Post, new { @class = "am-form-horizontal am-form" }))
                {
                    @Html.AmTestH(a => a.UserName)
                    @Html.AmTestH(a => a.Name)
                    @Html.AmTestH(a => a.Pwd)
                    @Html.AmTestH(a => a.Phone)
                    @Html.AmSelectH(a => a.RoleId, ViewBag.RoleId as IEnumerable<SelectListItem>, new { data_am_selected = "{searchBox: 1}" })
                    <div class="am-form-group  ">
                        <label class="am-u-sm-2 am-form-label am-padding-right">
                            上传文件
                        </label>
                        <div class="am-u-sm-10">
                            <div class="am-form-group am-form-file">
                                <button type="button" class="am-btn am-btn-danger am-btn-sm">
                                    <i class="am-icon-cloud-upload"></i> 选择要上传的文件
                                </button>
                                <input id="file" type="file" multiple>
                                 
                            </div><div id="file-list"></div>
                        </div>
                    </div>

                    <input  value="确定" type="submit" class="am-btn am-btn-primary  " />
                }

            </div>
        </div>
    </div>
</div>
@section scripts
{

    <script>

        var file = "#file";
        $(function () {

            $(file).on('change', function () {
                var fileNames = '';
                $.each(this.files, function () {
                    fileNames += '<span  class="am-badge">' + this.name + '</span> ';
                });
                $('#file-list').html(fileNames);
                up($(file)[0].files);
            });
        });
        function up(file) {
            for (var i = 0; i < file.length; i++) {
                var formdata = new FormData();
                var fileObj = file[i];
                formdata.append("file", fileObj);
                formdata.append("name", i);
                $.doUp('@Url.Action("Up")', formdata, function(d) {
                    if (!d.ms) {
                        $('#file-list .am-badge:eq(' + d.data + ')').addClass('am-badge-success');
                    }
                });
                 
            }
        }

        //function jindu() {
        //    var myDate = new Date();
        //    var gs = myDate.getSeconds();
        //    var x = 5;
        //    while (gs > x) {
        //        gs = gs - x;
        //    }
        //    var mm = (gs + (myDate.getMilliseconds() / 1000)) * 100 / (x + (myDate.getMilliseconds() / 1000));
        //    console.log(mm);
        //    $('.am-progress-bar').css('width', mm + '%').text(get(mm));

        //}
        //function get(num) {
        //    var s = num + "";
        //    var str = s.substring(0, s.indexOf(".") + 3);
        //    return str;
        //} window.setInterval('jindu()', 200);
    </script>
}